<?php

if (!defined('SYSPATH')) exit("No direct script access allowed!");

class CL_Exception extends Exception {

    public function CL_Exception($message = '', $code = 0) {
        $this->message = $message;
        $this->code = $code;
        log_message($this->message);
    }

    public function printJsonMessage() {

        ob_clean();
        ob_start();
        echo $this->getJsonMessage();
        exit();
    }

    public function getJsonMessage() {
        
        $exception = array('exception' => array(
                'name' => get_class($this),
                'message' => $this->message,
                'code' => $this->code
        ));

        return json_encode($exception);
    }

    public static function throw_json($message) {
        throw_json_exception(get_called_class(), $message);
    }
}


/* End of file CL_Exception.php */
/* Location: /system/libraries/CL_Exception.php */